package hh.engine;

import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

@Getter
public class Nodes {

    protected Reader reader;

    List<Node> list = new ArrayList<>();

    public void addNode(Node node) {
        this.list.add(node);
    }

    public Nodes(Reader reader) {
        this.reader = reader;

    }

    @Getter
    @Setter
    public class Node {
        int start;
        int end;
        String text;
        String body;

        @Override
        public String toString() {
            return "Node{" +
                    "start=" + start +
                    ", end=" + end +
                    ", text='" + text + '\'' +
                    ", body='" + body + '\'' +
                    '}';
        }

        public Node() {
        }

        public Node(int start, int end) {
            this.start = start;
            this.end = end;
            this.text = new String(reader.getData(), start, end - start);
            addNode(this);
        }
    }

    // <%  xxx %>
    public class Script extends Node {
        public Script(int start, int end) {
            super(start, end);
            this.body = new String(reader.getData(), start + 2, end - start - 4);
        }
    }

    // text
    public class Text extends Node {

        public Text(int start, int end) {
            super(start, end);
            this.body = text;
        }
    }

    // <%@ import
    public class Import extends Node {
        public Import(int start, int end) {
            super(start, end);
            this.body = new String(reader.getData(), start + 3, end - start - 5);
        }
    }

    // <%=
    public class Expr extends Node {
        public Expr(int start, int end) {
            super(start, end);
            this.body = new String(reader.getData(), start + 3, end - start - 5);
        }
    }
}
